package com.nbicc.anon.news.controller;

import com.nbicc.common.RequestPageObj;
import com.nbicc.common.ResponseObj;
import com.nbicc.news.po.NewsInfo;
import com.nbicc.news.service.INewsInfoService;
import com.nbicc.news.vo.NewsPreviousNext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Map;

@Api(value = "新闻描述(匿名)" , description = "新闻元数据")
@RestController
@RequestMapping(value = "/anon/news/info")
public class AnonNewsInfoController {

    @Resource(name = "NewsInfoServiceImpl")
    private INewsInfoService newsInfoService;

    @ApiOperation(value = "按id查询新闻描述" , notes = "单条")
    @GetMapping("/id/{id}")
    @ResponseBody
    public ResponseObj selectById(@PathVariable int id) throws Exception {
        NewsInfo newsInfo = newsInfoService.selectById(id);
        return ResponseObj.success().setResult(newsInfo);
    }

    @ApiOperation(value = "查询指定目录指定新闻前后的新闻", notes = "null就是没有")
    @GetMapping("/catId/{catId}/newsId/{newsId}")
    @ResponseBody
    public ResponseObj getPreviousAndNext(@PathVariable int catId,@PathVariable long newsId) {
        NewsPreviousNext newsPreviousNext = newsInfoService.getPreviousAndNext(catId, newsId);
        return ResponseObj.success().setResult(newsPreviousNext);
    }

    //↑crud========================================================================

    @ApiOperation(value = "按条件(分页等) 新闻描述", notes = "分页和条件查询 , 返回新闻元数据列表")
    @PostMapping("/find")
    @ResponseBody
    public ResponseObj find(@RequestBody RequestPageObj<Map<String,Object>> requestPageObj){
        ResponseObj responseObj = newsInfoService.find(requestPageObj);
        return responseObj;
    }

}
